package com.niiwoo.civet.scheduler.trigger;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.rpc.RpcContext;
import com.niiwoo.civet.trade.service.newRefund.RefundDubboService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.concurrent.CompletableFuture;

@Slf4j
@Component
public class NewRefundJobTrigger {

    @Reference(version = "1.0.0")
    private RefundDubboService refundDubboService;

    @Scheduled(cron = "${newRefund.freeze_deal_batch}")
    public void freezeDealBatch() {
        refundDubboService.freezeDealBatch();
    }

    @Scheduled(cron = "${newRefund.unfreeze_deal_batch}")
    public void unFreezeDealBatch() {
        refundDubboService.unFreezeDealBatch();
    }

    /**
     * 银行放款结果查询
     */
    @Scheduled(cron = "${newRefund.scheduled-run-bankRefundResultQuery}")
    public void bankRefundResultQuery() {
        CompletableFuture.runAsync(() -> refundDubboService.bankRefundResultQueryJob());
    }

    /**
     * 回款成功记账任务
     */
    @Scheduled(cron = "${newRefund.scheduled-run-receivedRepaymentSuccessAccounting}")
    public void receivedRepaymentSuccessAccountingJob() {
        CompletableFuture.runAsync(() -> refundDubboService.receivedRepaymentSuccessAccountingJob());

    }
    @Scheduled(cron = "${newRefund.scheduled-repeat-detail-order}")
    public void repeateDetailOrderForJob(){
        RpcContext.getContext().asyncCall(() -> refundDubboService.repeatDetailOrderForJob());
    }
}
